package cn.xenosp.server.module.userRole.service.impl;

import cn.xenosp.server.common.tools.IdUtil;
import cn.xenosp.server.common.tools.ObjectConvert;
import cn.xenosp.server.module.userRole.entity.SysUserRoleVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.xenosp.server.module.userRole.entity.SysUserRole;
import cn.xenosp.server.module.userRole.service.SysUserRoleService;
import cn.xenosp.server.module.userRole.mapper.SysUserRoleMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author Administrator
* @description 针对表【sys_user_role(用户和角色关联表)】的数据库操作Service实现
* @createDate 2025-01-01 14:41:27
*/
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole>
    implements SysUserRoleService{

    @Override
    public void userBindRole(String userId, List<SysUserRoleVO> roleList) {
        remove(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId,userId));

        List<SysUserRole> roleMenuList = new ArrayList<>();

        for (SysUserRoleVO roleVO : roleList) {
            SysUserRole userRole = new SysUserRole();
            ObjectConvert.copyVoToEntity(roleVO,userRole);
            userRole.setId(IdUtil.getId());
            roleMenuList.add(userRole);
        }

        baseMapper.insertBatch(roleMenuList);
    }
}




